package com.szzg10.webservice.chapter4;

import java.beans.XMLEncoder;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.List;

public class XMLEncoderMaker {

	private static final String fileName = "d:/temp/teams.ser";
	
	public static void main(String[] args) throws FileNotFoundException {
		
		FileOutputStream fileOutputStream = new FileOutputStream(fileName);
		XMLEncoder xmlEncoder = new XMLEncoder(fileOutputStream);
		
		List<Team> teams = makeList();
		xmlEncoder.writeObject(teams);
		xmlEncoder.close();
	}
	
	private static List<Team> makeList() {
		
		List<Player> players1 = new ArrayList<Player>();
		players1.add(new Player("Peter"));
		players1.add(new Player("Anne"));
		players1.add(new Player("Sue"));
		players1.add(new Player("Ken"));
		
		Team team1= new Team("Team1", players1);
		
		List<Player> players2 = new ArrayList<Player>();
		players2.add(new Player("Tim"));
		players2.add(new Player("Denis"));
		
		Team team2 = new Team("Team2",players2);
		
		List<Team> teams = new ArrayList<Team>();
		teams.add(team1);
		teams.add(team2);
		
		return teams;
	}
}
